(message "Loading ~/.emacs.d/init.el started")
(menu-bar-mode -1)
(scroll-bar-mode -1)
(tool-bar-mode -1)
(save-place-mode 1)
(electric-pair-mode 1)


(setq mac-option-key-is-meta t)
(setq mac-command-key-is-meta nil)
(setq mac-command-modifier 'super)
(setq mac-option-modifier 'meta)
(setq make-backup-files nil)

;; 设置无边框窗口
(setq-default ns-auto-hide-menu-bar t)  ;; 自动隐藏菜单栏
(setq-default ns-use-native-fullscreen nil)  ;; 禁用原生全屏
(setq-default ns-transparent-titlebar t) ;; 移除标题栏
(add-to-list 'default-frame-alist '(undecorated . t))


(setq frame-title-format '("%b – Emacs")
      icon-title-format frame-title-format)
(setq-default cursor-type 'bar)
(setq-default resize-mini-windows t)
(setq-default display-line-numbers-type nil)
(setq-default truncate-lines t)
(setq-default scroll-step 5)
(setq-default show-trailing-whitespace nil)
;;(visual-line-mode 1)

(setq-default c-basic-offset 4)
(setq-default python-indent-offset 4)
(setq-default tab-width 8)
(setq-default indent-tabs-mode nil)

(set-fringe-mode 1)
(set-frame-parameter nil 'minimal t)
(setq-default fringe-mode 'no-fringes)
(setq-default initial-major-mode 'org-mode)

(setq-default large-file-warning-threshold 500000000)
;;(setq-default mode-line-format nil)

(setq-default term-kill-buffer-on-exit t)
(setq dired-guess-shell-alist-user '(
                                     ("\\.mp4\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.mp3\\'" "ffplay -loglevel 8 -loop 0")
                                     ("\\.wav\\'" "ffplay -loglevel 8 -loop 0")
                                     ("\\.mov\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.webm\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.jpg\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.png\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.gif\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.jpeg\\'" "mpv --quiet --autofit-larger=100%x100% --loop=yes")
                                     ("\\.xmind\\'" "open -a Xmind")
                                     ("." "open -a Google\\ Chrome")
                                     ))

(setq default-input-method nil)

(setq dired-listing-switches "-alh")

(global-set-key (kbd "C-x K") 'kill-current-buffer)
;;(global-set-key (kbd "C-h") 'delete-backward-char) 
(global-set-key (kbd "C-u") 'kill-whole-line)
(global-set-key (kbd "C-x C-o") 'overwrite-mode)
(global-set-key (kbd "C-@") 'set-mark-command)
;;(global-set-key (kbd "C-s") 'isearch-forward-regexp) 
;;(global-set-key (kbd "C-r") 'isearch-backward-regexp)

(global-set-key (kbd "s-[") (lambda () (interactive) (adjust-opacity nil 5)))
(global-set-key (kbd "s-]") (lambda () (interactive) (adjust-opacity nil -5)))

(global-set-key (kbd "s-{") 'tab-previous)
(global-set-key (kbd "s-}") 'tab-next)
(global-set-key (kbd "s-t") 'tab-new)

(global-set-key (kbd "C-s-e") (lambda () (interactive) (find-file "~/.emacs.d/init.el")))
(global-set-key (kbd "C-s-,") (lambda () (interactive) (load-file "~/.emacs.d/init.el")))


(defun adjust-opacity (frame incr)
  "Adjust the opacity of the FRAME by increment INCR."
  (let* ((oldalpha (or (frame-parameter frame 'alpha) 100))
         (newalpha (min 100 (max 0 (+ incr oldalpha)))))
    (modify-frame-parameters frame (list (cons 'alpha newalpha)))))


;; 使用 pbcopy/pbpaste 与 macOS 系统剪贴板交互
(when (and (eq system-type 'darwin) (not (display-graphic-p)))
  (defun copy-to-clipboard (text &optional push)
    (let ((process-connection-type nil)) ;; 避免挂起
      (let ((proc (start-process "pbcopy" "*Messages*" "pbcopy")))
        (process-send-string proc text)
        (process-send-eof proc))))
  (defun paste-from-clipboard ()
    (shell-command-to-string "pbpaste"))
  (setq interprogram-cut-function 'copy-to-clipboard)
  (setq interprogram-paste-function 'paste-from-clipboard))


(defun c_w_redefine()                   
  "delele word or region depending on the mode"
  (interactive)
  (if (use-region-p)
      (kill-region (region-beginning)(region-end))
    (backward-kill-word 1)
      )
  )

(global-set-key (kbd "C-w") 'c_w_redefine)


(defun m_w_redefine()
  "copy current line or region"
  (interactive)
  (if (use-region-p)
      (progn
        (kill-ring-save (region-beginning) (region-end))
        )
    (progn
      (let ((current_col (current-column)))
      (kill-ring-save (line-beginning-position) (line-end-position))
      (move-end-of-line 1)
      (newline 1)
      (move-beginning-of-line 1)
      (yank)
      (move-to-column current_col)
      )
      )
    )
  )

(global-set-key (kbd "M-w") 'm_w_redefine)


(add-hook 'shell-mode-hook  'with-editor-export-editor)
(add-hook 'eshell-mode-hook 'with-editor-export-editor)
(add-hook 'term-exec-hook   'with-editor-export-editor)
(add-hook 'vterm-mode-hook  'with-editor-export-editor)

;;(global-set-key (kbd "C-@") 'rectangle-mark-mode)
(global-set-key (kbd "C-<tab>") 'tab-next)
(global-set-key (kbd "s-<escape>") 'next-window-any-frame)
(global-set-key (kbd "s-=") 'text-scale-increase)
(global-set-key (kbd "s--") 'text-scale-decrease)
(add-hook 'image-mode-hook
          (lambda ()
            (define-key image-mode-map (kbd "e") 'image-previous-file)
            (define-key image-mode-map (kbd "s-=") 'image-increase-size)
            (define-key image-mode-map (kbd "s--") 'image-decrease-size)))


(global-set-key (kbd "s-w") 'delete-frame)
(global-set-key (kbd "s-n") 'make-frame-command)


(global-set-key (kbd "M-t") 'treemacs)
(global-set-key (kbd "s-e") 'eshell)

(put 'upcase-region 'disabled nil)

(setq-default line-spacing 0)
;; (when (member "Songti SC" (font-family-list))
;;   (set-fontset-font t 'han (font-spec :family "Songti SC" :size 20)))

(put 'list-threads 'disabled nil)
(put 'set-goal-column 'disabled nil)


;;(pdf-tools-install)
(put 'dired-find-alternate-file 'disabled nil)

(add-hook 'server-done-hook 'delete-frame)


(defun my-disable-bar()
  (menu-bar-mode -1)
  (tool-bar-mode -1)
  (scroll-bar-mode -1)
  ;;(image-mode-fit-frame)
  (toggle-frame-maximized)
  )

(add-hook 'server-visit-hook 'my-disable-bar)
(add-hook 'after-make-frame-functions
          (lambda (frame)
            (menu-bar-mode -1)))

(require 'package)
(setq package-archives
      '(("melpa-stable" . "https://stable.melpa.org/packages/")
        ("gnu" . "https://elpa.gnu.org/packages/")))
(package-initialize)

(unless (package-installed-p 'use-package)
  (package-refresh-contents)
  (package-install 'use-package))



;; (use-package magit
;;   :ensure t
;;   :config
;;   (setq server-kill-new-buffers nil)
;;   (setq magit-diff-refine-hunks t
;;         magit-blame-display-style 'line-prefix
;;         magit-blame-show-author t
;;         magit-blame-show-date t)
;;   :defer t
;;   :bind ("C-c g" . magit-status)
;;   :config   ; 配置 magit
;;   (setq magit-auto-revert-mode t)  ; 自动刷新状态
;;   (setq magit-display-buffer-function #'magit-display-buffer-same-window-except-diff-v1)  ; 设置缓冲区显示方式
;;   )

(use-package diff-hl
  :ensure t
  :hook ((prog-mode . diff-hl-mode)
         (dired-mode . diff-hl-dired-mode))
  :config
  (global-diff-hl-mode))

(use-package rainbow-delimiters
  :ensure t
  :defer t
  :config
  (add-hook 'prog-mode-hook 'rainbow-delimiters-mode)
  )

(use-package pdf-tools
  :ensure t
  :init
  ;; 确保在启动时安装和初始化
  (pdf-tools-install)
  :config
  ;; 将 PDF 文件与 pdf-view-mode 关联
  (add-to-list 'auto-mode-alist '("\\.pdf\\'" . pdf-view-mode))
  ;; 设置默认的 PDF 查看模式
  (setq-default pdf-view-display-size 'fit-page)

  ;; 使用快捷键方便操作
  :bind (:map pdf-view-mode-map
              ("n" . pdf-view-next-page)       ;; 下一页
              ("e" . pdf-view-previous-page)   ;; 上一页
              ("+" . pdf-view-enlarge)         ;; 放大
              ("-" . pdf-view-shrink))         ;; 缩小

  ;; 启用持续渲染（提高性能）
  :custom
  (pdf-annot-activate-created-annotations t)
  )


;; Enable vertico
(use-package vertico
  :custom
  (vertico-scroll-margin 0) ;; Different scroll margin
  (vertico-count 10) ;; Show more candidates
  (vertico-resize t) ;; Grow and shrink the Vertico minibuffer
  (vertico-cycle t) ;; Enable cycling for `vertico-next/previous'
  :init
  (vertico-mode))

;; Persist history over Emacs restarts. Vertico sorts by history position.
(use-package savehist
  :init
  (savehist-mode))

;; A few more useful configurations...
(use-package emacs
  :custom
  ;; Support opening new minibuffers from inside existing minibuffers.
  (enable-recursive-minibuffers t)
  ;; Hide commands in M-x which do not work in the current mode.  Vertico
  ;; commands are hidden in normal buffers. This setting is useful beyond
  ;; Vertico.
  (read-extended-command-predicate #'command-completion-default-include-p)
  :init
  ;; Add prompt indicator to `completing-read-multiple'.
  ;; We display [CRM<separator>], e.g., [CRM,] if the separator is a comma.
  (defun crm-indicator (args)
    (cons (format "[CRM%s] %s"
                  (replace-regexp-in-string
                   "\\`\\[.*?]\\*\\|\\[.*?]\\*\\'" ""
                   crm-separator)
                  (car args))
          (cdr args)))
  (advice-add #'completing-read-multiple :filter-args #'crm-indicator)

  ;; Do not allow the cursor in the minibuffer prompt
  (setq minibuffer-prompt-properties
        '(read-only t cursor-intangible t face minibuffer-prompt))
  (add-hook 'minibuffer-setup-hook #'cursor-intangible-mode))

;; Optionally use the `orderless' completion style.
(use-package orderless
  :custom
  ;; Configure a custom style dispatcher (see the Consult wiki)
  (orderless-style-dispatchers '(+orderless-consult-dispatch orderless-affix-dispatch))
  (orderless-component-separator #'orderless-escapable-split-on-space)
  (completion-styles '(orderless basic))
  (completion-category-defaults nil)
  (completion-category-overrides '((file (styles partial-completion)))))


;; Option 1: Additional bindings
(keymap-set vertico-map "?" #'minibuffer-completion-help)
(keymap-set vertico-map "M-RET" #'minibuffer-force-complete-and-exit)
(keymap-set vertico-map "M-TAB" #'minibuffer-complete)

;; Option 2: Replace `vertico-insert' to enable TAB prefix expansion.
;; (keymap-set vertico-map "TAB" #'minibuffer-complete)

(setq completion-styles '(basic substring partial-completion flex))

(setq read-file-name-completion-ignore-case t
      read-buffer-completion-ignore-case t
      completion-ignore-case t)
;; Use `consult-completion-in-region' if Vertico is enabled.
;; Otherwise use the default `completion--in-region' function.
(setq completion-in-region-function
      (lambda (&rest args)
        (apply (if vertico-mode
                   #'consult-completion-in-region
                 #'completion--in-region)
               args)))


;; Configure directory extension.
(use-package vertico-directory
  :after vertico
  :ensure nil
  ;; More convenient directory navigation commands
  :bind (:map vertico-map
              ("RET" . vertico-directory-enter)
              ("DEL" . vertico-directory-delete-char)
              ("M-DEL" . vertico-directory-delete-word))
  ;; Tidy shadowed file names
  :hook (rfn-eshadow-update-overlay . vertico-directory-tidy))


;; Enable vertico-multiform
;;(vertico-multiform-mode)

;; Configure the display per command.
;; Use a buffer with indices for imenu
;; and a flat (Ido-like) menu for M-x.
(setq vertico-multiform-commands
      '((consult-imenu buffer indexed)
        (execute-extended-command unobtrusive)))

;; Configure the display per completion category.
;; Use the grid display for files and a buffer
;; for the consult-grep commands.
(setq vertico-multiform-categories
      '((file grid)
        (consult-grep buffer)))


(setq max-lisp-eval-depth 20000) ; Adjust the value as needed


;; (use-package evil
;;   :ensure t
;;   :init
;;   (setq evil-want-keybinding nil) ;; 不要自动绑定一些按键
;;   (setq evil-want-integration t)  ;; 让 Evil 与其他模式更好地集成
;;   (setq evil-want-C-u-scroll t)   ;; 让 C-u 继续滚动
;;   (setq evil-want-C-u-delete t)   ;; 让 C-u 在插入模式下删除整行（Emacs 默认行为）
;;   (setq evil-want-C-i-jump nil)                ;; 取消对 TAB (C-i) 的特殊处理
;;   (setq evil-respect-visual-line-mode t)       ;; 让 h/l 遵守 visual-line-mode
;;   (setq evil-disable-insert-state-bindings t)  ;; 让插入模式使用 Emacs 原生按键
;;   :config
;;   (evil-mode -1)
;;   (define-key evil-normal-state-map (kbd "SPC w") 'save-buffer)  ;; 空格+w 保存
;;   (define-key evil-normal-state-map (kbd "SPC q") 'kill-buffer)  ;; 空格+q 关闭 buffer
;;   (define-key evil-normal-state-map (kbd "C-a") 'move-beginning-of-line)  ;; C-a 移动到行首
;;   (define-key evil-normal-state-map (kbd "C-e") 'move-end-of-line)        ;; C-e 移动到行尾
;;   (define-key evil-normal-state-map (kbd "C-n") 'evil-next-visual-line)
;;   (define-key evil-normal-state-map (kbd "C-p") 'evil-previous-visual-line)
;;   (define-key evil-normal-state-map (kbd "C-f") 'evil-forward-char)
;;   (define-key evil-normal-state-map (kbd "C-b") 'evil-backward-char)
;;   (define-key evil-visual-state-map (kbd "C-a") 'move-beginning-of-line)  ;; C-a 移动到行首
;;   (define-key evil-visual-state-map (kbd "C-e") 'move-end-of-line)        ;; C-e 移动到行尾 
;;   (define-key evil-visual-state-map (kbd "C-f") 'evil-forward-char)
;;   (define-key evil-visual-state-map (kbd "C-b") 'evil-backward-char)
  
;;   (define-key evil-normal-state-map (kbd "C-q") 'projectile-find-file)
;;   ;; 让 ESC 退出插入模式并取消高亮
;;   (define-key evil-insert-state-map (kbd "ESC") 'evil-normal-state)
;;   (define-key evil-normal-state-map (kbd "<escape>") 'keyboard-quit)
;;   (define-key evil-visual-state-map (kbd "<escape>") 'keyboard-quit)
;;   ;; 重新映射 h j k l
;;   (evil-define-key 'normal 'global
;;     "h" 'evil-backward-char
;;     "n" 'evil-next-line
;;     "e" 'evil-previous-line
;;     "i" 'evil-forward-char
;;     "s" 'evil-insert
;;     ";" 'evil-ex
;;     )
;;   (evil-define-key 'visual 'global
;;     "h" 'evil-backward-char
;;     "n" 'evil-next-line
;;     "e" 'evil-previous-line
;;     "i" 'evil-forward-char
;;     ";" 'evil-ex
;;     )
;;   )

;; use-package with package.el:
(use-package dashboard
  :ensure t
  :config
  ;; emacsclient
  (setq initial-buffer-choice (lambda () (get-buffer-create dashboard-buffer-name)))
  ;; Set the title
  (setq dashboard-banner-logo-title "Welcome to Emacs Dashboard")
  ;; Set the logo
  (setq dashboard-startup-banner 'logo)
  ;; Content is not centered by default. To center, set
  (setq dashboard-center-content t)
  ;; vertically center content
  (setq dashboard-vertically-center-content t)
  ;; To disable shortcut "jump" indicators for each section, set
  (setq dashboard-show-shortcuts t)
  (setq dashboard-item-shortcuts '((recents   . "r")
                                 (bookmarks . "m")
                                 (projects  . "p")
                                 (agenda    . "a")
                                 (registers . "e")))
  (setq dashboard-icon-type 'all-the-icons)  ; use `all-the-icons' package
  (dashboard-setup-startup-hook))

(use-package doom-themes
  :ensure t
  :config
  ;; Global settings (defaults)
  (setq doom-themes-enable-bold t    ; if nil, bold is universally disabled
        doom-themes-enable-italic t) ; if nil, italics is universally disabled
  (load-theme 'doom-one t)

  ;; Enable flashing mode-line on errors
  (doom-themes-visual-bell-config)
  ;; Enable custom neotree theme (nerd-icons must be installed!)
  (doom-themes-neotree-config)
  ;; or for treemacs users
  (setq doom-themes-treemacs-theme "doom-atom") ; use "doom-colors" for less minimal icon theme
  (doom-themes-treemacs-config)
  ;; Corrects (and improves) org-mode's native fontification.
  (doom-themes-org-config))

(use-package doom-modeline
  :ensure t
  :init
  ;; 重点：**禁用 visual-bell**
  (setq visible-bell nil)  ;; 关闭 Emacs 的可视铃声
  (setq ring-bell-function 'ignore)  ;; 彻底忽略铃声触发
  (setq doom-modeline-hud nil)  ;; 关闭 `doom-modeline` 的 visual-bell 相关 UI
  :hook (after-init . doom-modeline-mode))

;; Example configuration for Consult
(use-package consult
  ;; Replace bindings. Lazily loaded by `use-package'.
  :bind (;; C-c bindings in `mode-specific-map'
         ("C-c M-x" . consult-mode-command)
         ("C-c h" . consult-history)
         ("C-c k" . consult-kmacro)
         ("C-c m" . consult-man)
         ("C-c i" . consult-info)
         ([remap Info-search] . consult-info)
         ;; C-x bindings in `ctl-x-map'
         ("C-x M-:" . consult-complex-command)     ;; orig. repeat-complex-command
         ("C-x b" . consult-buffer)                ;; orig. switch-to-buffer
         ("C-x 4 b" . consult-buffer-other-window) ;; orig. switch-to-buffer-other-window
         ("C-x 5 b" . consult-buffer-other-frame)  ;; orig. switch-to-buffer-other-frame
         ("C-x t b" . consult-buffer-other-tab)    ;; orig. switch-to-buffer-other-tab
         ("C-x r b" . consult-bookmark)            ;; orig. bookmark-jump
         ("C-x p b" . consult-project-buffer)      ;; orig. project-switch-to-buffer
         ;; Custom M-# bindings for fast register access
         ("M-#" . consult-register-load)
         ("M-'" . consult-register-store)          ;; orig. abbrev-prefix-mark (unrelated)
         ("C-M-#" . consult-register)
         ;; Other custom bindings
         ("M-y" . consult-yank-pop)                ;; orig. yank-pop
         ;; M-g bindings in `goto-map'
         ("M-g e" . consult-compile-error)
         ("M-g f" . consult-flymake)               ;; Alternative: consult-flycheck
         ("M-g g" . consult-goto-line)             ;; orig. goto-line
         ("M-g M-g" . consult-goto-line)           ;; orig. goto-line
         ("M-g o" . consult-outline)               ;; Alternative: consult-org-heading
         ("M-g m" . consult-mark)
         ("M-g k" . consult-global-mark)
         ("M-g i" . consult-imenu)
         ("M-g I" . consult-imenu-multi)
         ;; M-s bindings in `search-map'
         ("M-s d" . consult-find)                  ;; Alternative: consult-fd
         ("M-s c" . consult-locate)
         ("M-s g" . consult-grep)
         ("M-s G" . consult-git-grep)
         ("M-s r" . consult-ripgrep)
         ("M-s l" . consult-line)
         ("M-s L" . consult-line-multi)
         ("M-s k" . consult-keep-lines)
         ("M-s u" . consult-focus-lines)
         ;; Isearch integration
         ("M-s e" . consult-isearch-history)
         :map isearch-mode-map
         ("M-e" . consult-isearch-history)         ;; orig. isearch-edit-string
         ("M-s e" . consult-isearch-history)       ;; orig. isearch-edit-string
         ("M-s l" . consult-line)                  ;; needed by consult-line to detect isearch
         ("M-s L" . consult-line-multi)            ;; needed by consult-line to detect isearch
         ;; Minibuffer history
         :map minibuffer-local-map
         ("M-s" . consult-history)                 ;; orig. next-matching-history-element
         ("M-r" . consult-history))                ;; orig. previous-matching-history-element

  ;; Enable automatic preview at point in the *Completions* buffer. This is
  ;; relevant when you use the default completion UI.
  :hook (completion-list-mode . consult-preview-at-point-mode)

  ;; The :init configuration is always executed (Not lazy)
  :init

  ;; Tweak the register preview for `consult-register-load',
  ;; `consult-register-store' and the built-in commands.  This improves the
  ;; register formatting, adds thin separator lines, register sorting and hides
  ;; the window mode line.
  (advice-add #'register-preview :override #'consult-register-window)
  (setq register-preview-delay 0.5)

  ;; Use Consult to select xref locations with preview
  (setq xref-show-xrefs-function #'consult-xref
        xref-show-definitions-function #'consult-xref)

  ;; Configure other variables and modes in the :config section,
  ;; after lazily loading the package.
  :config

  ;; Optionally configure preview. The default value
  ;; is 'any, such that any key triggers the preview.
  ;; (setq consult-preview-key 'any)
  ;; (setq consult-preview-key "M-.")
  ;; (setq consult-preview-key '("S-<down>" "S-<up>"))
  ;; For some commands and buffer sources it is useful to configure the
  ;; :preview-key on a per-command basis using the `consult-customize' macro.
  (consult-customize
   consult-theme :preview-key '(:debounce 0.2 any)
   consult-ripgrep consult-git-grep consult-grep consult-man
   consult-bookmark consult-recent-file consult-xref
   consult--source-bookmark consult--source-file-register
   consult--source-recent-file consult--source-project-recent-file
   ;; :preview-key "M-."
   :preview-key '(:debounce 0.4 any))

  ;; Optionally configure the narrowing key.
  ;; Both < and C-+ work reasonably well.
  (setq consult-narrow-key "<") ;; "C-+"

  ;; Optionally make narrowing help available in the minibuffer.
  ;; You may want to use `embark-prefix-help-command' or which-key instead.
  ;; (keymap-set consult-narrow-map (concat consult-narrow-key " ?") #'consult-narrow-help)
)

;; (use-package lsp-mode
;;   :ensure t
;;   :init
;;   ;; set prefix for lsp-command-keymap (few alternatives - "C-l", "C-c l")
;;   (setq lsp-keymap-prefix "C-c l")
;;   :hook (;; replace XXX-mode with concrete major-mode(e. g. python-mode)
;;          ;; (company-mode . lsp)
;;          ;;(python-mode . lsp)
;;          (go-mode . lsp)
;;          (js-mode . lsp)
;;          (typescript-mode . lsp)
;;          (rust-mode . lsp)
;;          (c-mode . lsp)
;;          (c++-mode . lsp)
;;          (java-mode . lsp)
;;          ;; if you want which-key integration
;;          (lsp-mode . lsp-enable-which-key-integration))
;;   :config
;;   (setq lsp-auto-guess-root t)
;;   (setq lsp-log-io nil)
;;   (setq lsp-enable-snippet t)
;;   (setq lsp-enable-indentation t)
;;   (setq lsp-enable-on-type-formatting t)
;;   (setq lsp-enable-symbol-highlighting t)
;;   (setq lsp-headerline-breadcrumb-enable nil)
;;   (setq lsp-enable-file-watchers t)
;;   (setq lsp-enable-folding t)
;;   (setq lsp-byte-string-plists-max 65535) ; Adjust the value if needed (e.g., 131072 for 128kb)
;;   ;; (setq lsp-completion-provider :capf)
;;   (setq read-process-output-max (* 1024 1024)) ;; 1mb
;;   (setq gc-cons-threshold (* 1024 1024 4)) ; Adjust the multipliers for megabytes
;;   :commands lsp)

;;
;;(use-package lsp-pyright
;;  :ensure t
;;  :after lsp-mode
;;  :config   ; 配置 lsp-pyright
;;  (setq lsp-pyright-auto-search-paths nil)  ; 禁用自动搜索路径
;;  (setq lsp-pyright-auto-import-completions t)  ; 启用自动导入补全
;;  (setq lsp-pyright-use-library-code-for-types t)  ; 使用库代码进行类型推断
;;  )

;; 配置 pyvenv
;; (use-package pyvenv
;;   :ensure t
;;   :config
;;   (pyvenv-mode t))

;; (setq tree-sitter-major-mode-language-alist
;; optional if you want which-key integration
(use-package which-key
    :config
    (which-key-mode))

(use-package drag-stuff
  :ensure t
  :config
  (drag-stuff-mode t)  ; 启用 drag-stuff 模式
  (setq drag-stuff-except-modes '(org-mode))  ; 在 org-mode 中禁用
  :bind
  (("M-p" . drag-stuff-up)    ; 向上移动文本
   ("M-n" . drag-stuff-down)  ; 向下移动文本
   ("M-<up>" . drag-stuff-up)   ; 使用 M-<up> 向上移动
   ("M-<down>" . drag-stuff-down))) ; 使用 M-<down> 向下移动


(use-package org
  :ensure t ; 确保 Org-mode 已经安装（默认安装在 Emacs 中）
  :custom
  ;; 启用图片显示
  (org-startup-with-inline-images t)
  ;; 设置 Org-mode 的字体大小和样式
  (org-hide-emphasis-markers t)
  (org-startup-indented t)  ; 启用缩进，提升可读性
  (org-ellipsis " ▼")      ; 折叠时显示的符号
  (org-pretty-entities t)   ; 启用显示漂亮的数学符号
  :config
  ;; 自定义 Org-mode 设置
  (setq org-agenda-files '("~/Documents/agenda.org"))  ; 设置 agenda 文件的位置
  (setq org-capture-templates
        '(("t" "Todo" entry (file+headline "~/Documents/gtd.org" "Tasks")
           "* TODO %?\n  %i\n  %a"))) ; 定义任务捕获模板
  (setq org-log-done 'time) ; 记录任务完成时间
  ;; 允许导出为不同格式
  (setq org-export-backends '(ascii html latex md))  ; 设置导出的格式
  ;; 启用并配置 Org-babel
  (org-babel-do-load-languages
   'org-babel-load-languages
   '((python . t)        ; 启用 Python 代码块
     (shell . t)         ; 启用 Shell 代码块
     (emacs-lisp . t)))  ; 启用 Emacs Lisp 代码块
  ;; 自动显示图片
  (add-hook 'org-mode-hook 'org-display-inline-images)
  (add-hook 'org-mode-hook 'valign-mode)
  (add-hook 'org-mode-hook 'org-bullets-mode)
  (add-hook 'org-mode-hook 'org-indent-mode)
  (add-hook 'org-mode-hook 'visual-line-mode)
  )

;; 使用 use-package 配置 projectile
(use-package projectile
  :ensure t  ; 自动安装 projectile
  :init     ; 初始化设置
  (projectile-mode +1)  ; 启用 projectile 模式
  :bind     ; 绑定快捷键
  (("C-c p" . projectile-command-map)  ; 将 C-c p 绑定到 projectile 命令映射
   ("C-x c" . projectile-compile-project)
   ("C-x f" . projectile-find-file)
   ("C-x e" . project-eshell)
   )
  :config   ; 配置 projectile
  (setq projectile-project-search-path '("~/code/"))  ; 设置项目搜索路径
  (setq projectile-switch-project-action 'projectile-dired)  ; 切换项目时打开 dired
  (setq projectile-enable-caching t)  ; 启用缓存以加快性能
  (setq projectile-completion-system 'default)  ; 使用默认补全系统
  (setq projectile-indexing-method 'alien)  ; 使用外部工具加速索引
  (setq projectile-require-project-root t))  ; 仅在项目根目录下启用 projectile

(custom-set-variables
 ;; custom-set-variables was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(cursor-type 'bar)
 '(custom-safe-themes
   '("02f57ef0a20b7f61adce51445b68b2a7e832648ce2e7efb19d217b6454c1b644" "e3daa8f18440301f3e54f2093fe15f4fe951986a8628e98dcd781efbec7a46f2" "adaf421037f4ae6725aa9f5654a2ed49e2cd2765f71e19a7d26a454491b486eb" default))
 '(evil-undo-system 'undo-redo)
 '(menu-bar-mode nil)
 '(package-selected-packages
   '(valign all-the-icons evil which-key vertico undo-tree tree-sitter sexy-monochrome-theme rainbow-delimiters projectile pdf-tools org-bullets orderless lua-mode drag-stuff doom-themes doom-modeline diff-hl dashboard consult company))
 '(send-mail-function 'mailclient-send-it))
(custom-set-faces
 ;; custom-set-faces was added by Custom.
 ;; If you edit it by hand, you could mess it up, so be careful.
 ;; Your init file should contain only one such instance.
 ;; If there is more than one, they won't work right.
 '(default ((t (:family "Courier New" :weight bold :height 200)))))
;; 设置默认字体

(message "Loading ~/.emacs.d/init.el completed")




